package com.ldg.manager.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ld.utils.PageUtils;
import com.ld.pojo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ldg.manager.entity.ItemCatEntity;
import com.ldg.manager.service.ItemCatService;




/**
 * 商品类目
 *
 * @author LD
 * @email 419631142@qq.com
 * @date 2022-09-12 18:39:33
 */
@RestController
@RequestMapping("itemcat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = itemCatService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 查询所有分类
     * @return
     */
    @GetMapping("findAll")
    public R findAll(){
        List<ItemCatEntity> itemCats = itemCatService.findAll();
        return R.ok().put("list",itemCats);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		ItemCatEntity itemCat = itemCatService.getById(id);

        return R.ok().put("itemCat", itemCat);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody ItemCatEntity itemCat){
		itemCatService.save(itemCat);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody ItemCatEntity itemCat){
		itemCatService.updateById(itemCat);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids){
		itemCatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
